﻿using GN.Pay.TradeChannel.YJPay.Response;
using GN.Pay.Utils.Net.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace GN.Pay.TradeChannel.YJPay.Request
{
    [Serializable]
    class QueryRequest : AServiceRequest
    {
        private ITradeChannel channel;
        private YJPayConfigure config;

        public QueryRequest(ITradeChannel channel,
             YJPayConfigure config, string orderNo)
        {
            this.channel = channel;
            this.config = config;
            this.orderNo = DateTime.Now.ToString("yyyyMMddHHmmssfff");
            merchantOrderNos = orderNo;
            version = "1.0";
            tradeNos = "";
            partnerId = config.ConfigureInfo.AccountId;
            //billNo = orderNo;
            //this.billNoType = "1";
        }

        public override string service
        {
            get
            {
                return "multipleTradeMergeQuery";
               // return "tradeInfoQuery";
            }
        }

        /// <summary>
        /// 查询重新生成订单号
        /// </summary>
        public string orderNo { get; set; }

        //public string billNo { get; set; }

        //public string billNoType { get; set; }

        /// <summary>
        /// /需要传入创建交易时的merchOrderNo 
        /// </summary>
        public string merchantOrderNos { get; set; }

        /// <summary>
        /// 原交易号
        /// </summary>
        public string tradeNos { get; set; }

        /// <summary>
        /// 版本号
        /// </summary>
        public string version { get; set; }

        /// <summary>
        /// 生成
        /// </summary>
        /// <returns></returns>
        public QueryResponse Build()
        {
            var param = this.BuildSignDictionary(channel, config);
            param = param.Clone(k =>
            {
                return k;
            }, v =>
            {
                return HttpUtility.UrlEncode(v, config.Encoding);
            });
            string url = config.GatewayUrl + "?";
            string responseString = HttpUtils.PostString(url, param, config.Encoding);
            return new QueryResponse(responseString, channel, config);
        }
    }
}
